float4x4 World;
float4x4 View;
float4x4 Projection;


texture2D normal;

sampler2D normalSampler = sampler_state 
{
    texture = normal;
    AddressU = CLAMP;
    AddressV = CLAMP;
    FILTER = POINT;
};

texture2D position;

sampler2D positionSampler = sampler_state
{
	texture = position;
	AddressU = CLAMP;
	AddressV = CLAMP;
	FILTER = POINT;
};

texture2D projtex;

sampler2D projtexture = sampler_state
{
    texture = projtex;
    AddressU = CLAMP;
    AddressV = CLAMP;
    FILTER = LINEAR;
};

texture2D Diffuse;

sampler2D ColorMapSampler = sampler_state 
{
    texture = Diffuse;
    AddressU = CLAMP;
    AddressV = CLAMP;
    FILTER = POINT;
};

struct VertexShaderInput
{
    float4 Position : POSITION0;
    float3 TexCoords : TEXCOORD0;
    float3 Normal : NORMAL0;
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
    float3 TexCoords : TEXCOORD0;
    float3 Normal : TEXCOORD1;
    float4 Wpos : TEXCOORD2;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);

    output.TexCoords = input.TexCoords;
    output.Normal = mul(input.Normal, World);
    output.Wpos = worldPosition;

    return output;
}

struct PSO
{
	float4 Target0 : COLOR0;
	float4 Target1 : COLOR1;
};

PSO PixelShaderFunction(VertexShaderOutput input)
{
	PSO output;
	
	output.Target0 = input.Wpos;
	output.Target1 = float4(input.Normal, 0);
	
    return output;
}

float4 PixelShaderFunctionFilter(VertexShaderOutput input) :COLOR0
{
	float3 lightDir = normalize(float3(1.0, 1.0, 0.0));
	float3 secondLightDir = normalize(float3(-1.0, 1.0, 0.0));
	float3 thirdLightDir = normalize(float3(1.0, -1.0, 0.0));
	float3 fourthLightDir = normalize(float3(-1.0, -1.0, 0.0));
	float3 normal = normalize(tex2D(normalSampler, input.TexCoords).xyz);
	
	float diffuse = dot(normal, lightDir);
	float secondDiffuse = dot(normal, secondLightDir);
	float thirdDiffuse = dot(normal, thirdLightDir);
	float fourthDiffuse = dot(normal, fourthLightDir);
	
	float4 color1 = float4(diffuse, diffuse, diffuse, 1);
	float4 color2 = float4(diffuse, diffuse, diffuse, 1) + float4(secondDiffuse, secondDiffuse, secondDiffuse, 1);
	float4 color3 = float4(diffuse, diffuse, diffuse, 1) + float4(secondDiffuse, secondDiffuse, secondDiffuse, 1) + float4(thirdDiffuse, thirdDiffuse, thirdDiffuse, 1);
	float4 color4 = float4(diffuse, diffuse, diffuse, 1) + float4(secondDiffuse, secondDiffuse, secondDiffuse, 1) + float4(thirdDiffuse, thirdDiffuse, thirdDiffuse, 1) + float4(fourthDiffuse, fourthDiffuse, fourthDiffuse, 1);
	
	return color3;
}

technique OOC
{
    pass Pass1
    {
        VertexShader = compile vs_3_0 VertexShaderFunction();
        PixelShader = compile ps_3_0 PixelShaderFunction();
    }
}

technique PostProcess
{
    pass Pass1
    {
        VertexShader = compile vs_3_0 VertexShaderFunction();
        PixelShader = compile ps_3_0 PixelShaderFunctionFilter();
    }
}